package com.yue92.datalife.config;

import com.yue92.datalife.model.queue.EmailMsg;
import com.yue92.datalife.model.queue.PushMsg;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.kafka.annotation.KafkaHandler;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

@Component
@Slf4j
@KafkaListener(topics = "${kafka.topic.queue}")
public class ConsumerHandler implements InitializingBean {

    @Getter
    private static String topicQueue;

    @Value("${kafka.topic.queue}")
    private String topicQueueField;

    @Override
    public void afterPropertiesSet() throws Exception {
        topicQueue = topicQueueField;
    }

    @KafkaHandler
    public void listen(PushMsg in) {
        log.info("KafkaConsumerHandler PushMsg listen {}", in);
    }

    @KafkaHandler
    public void listen(EmailMsg in) {
        log.info("KafkaConsumerHandler EmailMsg listen {}", in);
    }
}
